#pragma once

#include <linux/swait.h>

struct completion
{
    unsigned int done;
    struct swait_queue_head wait;
};

#define COMPLETION_INITIALIZER(work) \
    {.done = 0, .wait = __SWAIT_QUEUE_HEAD_INITIALIZER((work).wait)}

/**
 * DECLARE_COMPLETION - declare and initialize a completion structure
 * @work:  identifier for the completion structure
 *
 * This macro declares and initializes a completion structure. Generally used
 * for static declarations. You should use the _ONSTACK variant for automatic
 * variables.
 */
#define DECLARE_COMPLETION(work) \
    struct completion work = COMPLETION_INITIALIZER(work)

void init_completion(struct completion *x);

void complete(struct completion *x);

bool completion_done(struct completion *x);
void wait_for_completion(struct completion *x);
